package top.zt9.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardReport;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.zt9.service.ElasticsearchService;

import java.io.IOException;

/**
 * @Author ztf
 * @Date 15:53 2021/11/27
 **/
@Component
public class UpdateLogListener {
    @Autowired
    private ElasticsearchService elasticsearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void updateLog(StandardReport standardReport, Channel channel, Message message) throws IOException {

        //调用service
        elasticsearchService.updateLog(standardReport);

        //手动ACK
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
